uniform sampler2D mainTexture;
uniform float textureSize;

uniform float bloomDistance;
uniform int bloomSamples;
uniform float blurMean;
uniform vec2 dispV;

varying vec2 texCoord;

float bloomValue(in float xdisp, in float standardDev)
{
	return exp(-xdisp*xdisp/(2.0*standardDev*standardDev)) / (2.50662827*standardDev);
}

void main()
{
	float standardDev = exp(-blurMean);
	vec3 sample, color;
	color = vec3(0,0,0);
	for(int x=-bloomSamples;x<=bloomSamples;x++)
	{
		float xdisp = float(x)/textureSize;
		sample =texture2D(mainTexture,texCoord+dispV*vec2(xdisp)).rgb;

		float distdisp = float(x)/float(2*bloomSamples+1);
		float blurValue= bloomValue(distdisp,standardDev)/float(bloomSamples*2);

		color+=sample * blurValue;
	}
	gl_FragColor.rgb = pow(color,vec3(1.1))/ (1.0+blurMean) * 4.0;
	gl_FragColor.a = 1.0;
}


